import request from '@/utils/request'
import axios from 'axios'

// 获取成员列表
export function getMemberList(params) {
  return request({
    url: '/members',
    method: 'get',
    params
  })
}

// 获取成员详情
export function getMemberDetail(id) {
  return request({
    url: `/members/${id}`,
    method: 'get'
  })
}

// 添加成员
export function addMember(data) {
  return request({
    url: '/members',
    method: 'post',
    data
  })
}

// 更新成员
export function updateMember(id, data) {
  return request({
    url: `/members/${id}`,
    method: 'put',
    data
  })
}

// 删除成员
export function removeMember(id) {
  return request({
    url: `/members/${id}`,
    method: 'delete'
  })
}

// 审核通过成员
export function approveMember(id) {
  return request({
    url: `/members/${id}/approve`,
    method: 'post'
  })
}

// 拒绝成员申请
export function rejectMember(id, reason) {
  return request({
    url: `/members/${id}/reject`,
    method: 'post',
    data: { reason }
  })
}

// 发送邀请
export function sendInvitation(data) {
  return request({
    url: '/members/invite',
    method: 'post',
    data
  })
}

// 获取邀请链接
export function getInviteLink() {
  return request({
    url: '/members/invite-link',
    method: 'get'
  })
}

// 导出成员信息
export function exportMembers(params) {
  const baseURL = 'http://localhost:8081/api'
  const token = localStorage.getItem('token')
  
  return axios({
    url: `${baseURL}/members/export`,
    method: 'get',
    params,
    responseType: 'blob',
    headers: token ? { 'Authorization': `Bearer ${token}` } : {}
  })
} 